package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AuthorityDao;
import com.itheima.dao.PermissionMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Permission;
import com.itheima.pojo.QueryPageBean;
import com.itheima.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @version V1.0
 * @author: sujiahao
 * @date: 2020/2/12 11:24
 * @description:
 */
@Service(interfaceClass = AuthorityService.class)
@Transactional
public class AuthorityServiceImpl implements AuthorityService{

    @Autowired
    private AuthorityDao authorityDao;
    @Autowired
    private PermissionMapper permissionMapper;


    @Override
    public PageResult queryPage(QueryPageBean queryPageBean) {
        //使用分页插件,
        Page page= PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<Permission> authority=authorityDao.queryPage(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),authority);
    }

    @Override
    public void add(Permission permission) {
        permissionMapper.insert(permission);
    }

    /**
     * 根据id查出数据进行数据编辑时数据的回显
     * @param id
     * @return
     */
    @Override
    public Permission queryById(Integer id) {
        Permission permission=authorityDao.queryById(id);
        return permission;
    }

    @Override
    public void deleteById(Integer id) {
        permissionMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改权限数据
     * @param permission
     */
    @Override
    public void updataById(Permission permission) {
        permissionMapper.updateByPrimaryKeySelective(permission);
    }
}
